﻿using AutoMapper;
using DncLite.Application.ViewModels.Student;
using DncLite.Domain.Commands.Student;
using DncLite.Domain.Models;

namespace DncLite.Application.AutoMapper
{
    /// <summary>
    /// 视图模型 -> 领域模型 映射配置类
    /// </summary>
    internal class ViewModelToDomainMappingProfile : Profile
    {
        public ViewModelToDomainMappingProfile()
        {
            CreateMap<StudentViewModel, Student>()
                .ForPath(d=>d.Address.Province,o=>o.MapFrom(s=>s.Province))
                .ForPath(d => d.Address.City, o => o.MapFrom(s => s.City))
                .ForPath(d => d.Address.County, o => o.MapFrom(s => s.County))
                .ForPath(d => d.Address.Street, o => o.MapFrom(s => s.Street));

            CreateMap<StudentViewModel, RegisterStudentCommand>()
                .ConstructUsing(c => new RegisterStudentCommand(c.Name, c.Email, c.BirthDate, c.Phone));
        }
    }
}